* Clear
  clear  
  
* Working Directory
  cd "~/Replication Materials for The Domestic Economic Costs of Sanctions - A Firm Level Analysis/"

* Log File
  log using "table1.log", replace   
  
* Table 1 Models  
  
  * Eli Lilly (1989)
  
    * Load data
	  use "rcs.dta"

    * Generate Returns
	  gen lly_returns = ln(lly_close/lly_close[_n-1])
    
	* Sanctions
	  gen tsanction3 = 1 if date > td("04jun1989") & date < td("25may1990")
	  recode tsanction3(.=0)
	
    * Bond Market Crash
	  gen f13minicrash = 1 if date > td("11oct1989") & date < td("17oct1989")
	  recode f13minicrash(.=0)
	  
    * Limit Time Period
      keep if date > td("30dec1988") & date < td("01jun1990")
		
    * Set for analysis
	  tsset t
	  
	* Model 1 (LLY 1989)
	  eststo clear
	  
	  eststo: arch lly_returns, ar(4) arch(22)
	  
	  predict e, residuals
      predict v, variance
      gen s = sqrt(v)
      gen se = e/s
      gen se2 = se^2
      
	  ac se
	  pac se
	  wntestq se
	  
      ac se2
      pac se2
      wntestq se2
	  
    * Model 2 (LLY 1989)
	  eststo: arch lly_returns, ar(4) arch(22) het(tsanction3 f13minicrash)
	  
	  drop e v s se se2
	  
	  predict e, residuals
      predict v, variance
      gen s = sqrt(v)
      gen se = e/s
      gen se2 = se^2
      
	  ac se
	  pac se
	  wntestq se
	  
      ac se2
      pac se2
      wntestq se2
	  
  * Pfizer (1989)	
  
    * Clear
	  clear
	
	* Load Data
      use "rcs.dta"

    * Generate Returns
	  gen pfe_returns = ln(pfe_close/pfe_close[_n-1])
    
	* Sanctions
	  gen tsanction3 = 1 if date > td("04jun1989") & date < td("25may1990")
	  recode tsanction3(.=0)
	
    * Bond Market Crash
	  gen f13minicrash = 1 if date > td("11oct1989") & date < td("17oct1989")
	  recode f13minicrash(.=0)
	  
    * Limit Time Period
      keep if date > td("30dec1988") & date < td("01jun1990")
	  
	* Model 3 (PFE 1989)
	  eststo: arch pfe_returns, ar(1) arch(1,3)
	  
	  predict e, residuals
      predict v, variance
      gen s = sqrt(v)
      gen se = e/s
      gen se2 = se^2
      
	  ac se
	  pac se
	  wntestq se
	  
      ac se2
      pac se2
      wntestq se2
	  
    * Model 4 (PFE 1989)
	  eststo: arch pfe_returns, ar(1) arch(1,3) het(tsanction3 f13minicrash)
	  
	  drop e v s se se2
	  
	  predict e, residuals
      predict v, variance
      gen s = sqrt(v)
      gen se = e/s
      gen se2 = se^2
      
	  ac se
	  pac se
	  wntestq se
	  
      ac se2
      pac se2
      wntestq se2
	  
  * Bed Bath and Beyond 2011
  
    * Clear
	  clear
	  
	* Load Data
	  use "rcs.dta"
  
    * Generate Returns
	  gen bbby_returns = ln(bbby_close/bbby_close[_n-1])
    
    * Currency Sanctions
      gen csanction = 1 if date > td("11jul2011") & date < td("18oct2011")
      recode csanction(.=0)

    * Debt Debate
      gen debt = 1 if date > td("13may2011") & date < td("01aug2011")
      recode debt(.=0)

    * Black Mondayd		
      gen bmonday = 1 if date > td("01aug2011") & date < td("15aug2011")
      recode bmonday(.=0)

    * Limit Time Period
      keep if date > td("31dec2010") & date < td("03jan2012")	
		
    * Set for analysis
	  tsset t
	  
	* Model 5 (BBBY 2011)
	  eststo: arch bbby_returns
	  
	  predict e, residuals
      predict v, variance
      gen s = sqrt(v)
      gen se = e/s
      gen se2 = se^2
      
	  ac se
	  pac se
	  wntestq se
	  
      ac se2
      pac se2
      wntestq se2
	  
    * Model 6 (BBBY 2011)
	  eststo: arch bbby_returns, het(bmonday debt csanction)
	  
	  drop e v s se se2
	  
	  predict e, residuals
      predict v, variance
      gen s = sqrt(v)
      gen se = e/s
      gen se2 = se^2
      
	  ac se
	  pac se
	  wntestq se
	  
      ac se2
      pac se2
      wntestq se2
	  
  * Gap (2011)
  
    * Clear
	  clear
	  
	* Load Data
	  use "rcs.dta"
  
    * Generate Returns
	  gen gps_returns = ln(gps_close/gps_close[_n-1])
    
    * Currency Sanctions
      gen csanction = 1 if date > td("11jul2011") & date < td("18oct2011")
      recode csanction(.=0)

    * Debt Debate
      gen debt = 1 if date > td("13may2011") & date < td("01aug2011")
      recode debt(.=0)

    * Black Mondayd		
      gen bmonday = 1 if date > td("01aug2011") & date < td("15aug2011")
      recode bmonday(.=0)
	  
	* Gap Report
      gen report = 1 if date > td("18may2011") & date < td("24may2011")
      recode report(.=0)  

    * Limit Time Period
      keep if date > td("31dec2010") & date < td("03jan2012")	
	  
	* Model 7 (GPS 2011)
	  eststo: arch gps_returns
	  
	  predict e, residuals
      predict v, variance
      gen s = sqrt(v)
      gen se = e/s
      gen se2 = se^2
      
	  ac se
	  pac se
	  wntestq se
	  
      ac se2
      pac se2
      wntestq se2
	  
    * Model 8 (GPS 2011)
	  eststo: arch gps_returns, het(bmonday debt csanction report)
	  
	  drop e v s se se2
	  
	  predict e, residuals
      predict v, variance
      gen s = sqrt(v)
      gen se = e/s
      gen se2 = se^2
      
	  ac se
	  pac se
	  wntestq se
	  
      ac se2
      pac se2
      wntestq se2
	  
  * Generate Table
    esttab, b(3) se(3) star(* .10 ** .05 *** .01) scalars(aic bic) nogaps compress coeflabels(_cons Constant tsanction3 Sanction1 f13minicrash MiniCrash csanction Sanction2 debt DebtDebate bmonday BlackMonday) nomtitles title(Within Sectors Within Years) nodep
    esttab using rawtables/table1raw.tex, b(3) se(3) star(* .10 ** .05 *** .01) scalars(aic bic) nogaps compress coeflabels(_cons Constant tsanction3 Sanction1 f13minicrash MiniCrash csanction Sanction2 debt DebtDebate bmonday BlackMonday) nomtitles title(Within Sectors Within Years) nodep
	
* Close Log File
  log close	
	
